package org.totoro.patterns.behavior.chain.of.responsebility;

import java.util.StringJoiner;

/**
 * Created by renkai on 2017/3/21.
 */
public class MyHandler extends AbstractHandler implements Handler {
    private String name;

    public MyHandler(String name) {
        this.name = name;
    }

    public MyHandler(String name, Integer sort) {
        this.name = name;
        super.setSortIndex(sort);
    }

    public String getName() {
        return name;
    }

    public MyHandler setName(String name) {
        this.name = name;
        return this;
    }

    @Override
    public void operator() {
        System.out.println(name + "deal");
        if (getHandler() != null) {
            getHandler().operator();
        }
    }

    @Override
    public String toString() {
        return new StringJoiner(", ", MyHandler.class.getSimpleName() + "[", "]")
                .add("name='" + name + "'")
                .toString();
    }


}
